
(function($){  
        $.fn.serializeJson=function(){  
            var serializeObj={};  
            var array=this.serializeArray();  
            var str=this.serialize();  
            $(array).each(function(){  
                if(serializeObj[this.name]){  
                    if($.isArray(serializeObj[this.name])){  
                        serializeObj[this.name].push(this.value);  
                    }else{  
                        serializeObj[this.name]=[serializeObj[this.name],this.value];  
                    }  
                }else{  
                    serializeObj[this.name]=this.value;   
                }  
            });  
            return serializeObj;  
        };  
 })(jQuery);  
$(function(){
	$('.customTip').tooltip({
	    position: 'right', 
	    onShow: function(){
	    $(this).tooltip('tip').css({
	    backgroundColor: '#666',
	    borderColor: '#666'
	    });
	    }
	 });
	 $(".edit-item").focus(function(){
		   if($(this).val()==$(this).attr("title")){
		      $(this).val("");
		   };
		  }).blur(function(){
		   if($(this).val()==''){
		      $(this).val($(this).attr("title")).css("color","#ccc");
		   };
	  }); 
	 $('.customValidTip').validatebox({
		 tipOptions: { // the options to create tooltip
			 showEvent: 'mouseenter',
			 hideEvent: 'mouseleave',
			 showDelay: 0,
			 hideDelay: 0,
			 zIndex: '',
			 onShow: function(){
				 if (!$(this).hasClass('validatebox-invalid')){
					 if ($(this).tooltip('options').prompt){
					 $(this).tooltip('update', $(this).tooltip('options').prompt);
					 } else {
					 $(this).tooltip('tip').hide();
					 }
				 } else {
					 $(this).tooltip('tip').css({
						 color: '#000',
						 borderColor: '#CC9933',
						 backgroundColor: '#FFFFCC'
					 });
				 }
			 },
			 onHide: function(){
				 if (!$(this).tooltip('options').prompt){
					 $(this).tooltip('destroy');
				 }
			 }
		 }
	 }).tooltip({
		 position: 'right',
		 content: function(){
		 var opts = $(this).validatebox('options');
		 return opts.prompt;
		 },
		 onShow: function(){
			 $(this).tooltip('tip').css({
			 color: '#000',
			 borderColor: '#CC9933',
			 backgroundColor: '#FFFFCC'
			 });
		 }
     });
});

//屏蔽只读组件的删除事件。页面中不可编辑元素下按backspace键会使浏览器后退到上一个页面。
//好像只有在IE下会有此问题，FF中没有此问题。
document.onkeydown = function(e) {
	// IE不传e,使用window.event获得；firefox则从e中获得事件
	var event = e || window.event;
	var key = event.keyCode || event.which;
	// var type=event.srcElement.type||event.target.type;
	// var stat=event.srcElement.readOnly||event.target.readOnly;
	if (event.srcElement) {
		var type = event.srcElement.type;
		var stat = event.srcElement.readOnly;
	} else if (event.target) {
		var type = event.target.type;
		var stat = event.target.readOnly;
	}
	if (key == 8) { // 删除键的keyCode为8
		if ((type != "text" && stat == true)
				|| (type != "textarea" && stat == true)
				|| (type != "select" && stat == true)) {
			event.keyCode = 0;
			event.returnValue = false;
		}
	}
};



/**
 *     loadScript("script1.js", function(){  
           alert("File is loaded!");  
       });  
       
    loadScript("script1.js", function(){  
        loadScript("script2.js", function(){  
            loadScript("script3.js", function(){  
                alert("All files are loaded!");  
            });  
        });  
    });  
 * @param url
 * @param callback
 */
function loadScript(url, callback){
    var script = document.createElement("script");
    script.type = "text/javascript";
    if (script.readyState){ //IE
        script.onreadystatechange = function(){
            if (script.readyState == "loaded" || script.readyState == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else { //Others
        script.onload = function(){
            callback();
        };
    }
    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}